﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnnealingModel.Demo.Common.Function
{
    [DisplayText(FunctionType.UnaryFunction6, "y=Σa^ncos(b^nπx)")]
    internal class UnaryFunction6 : FuntionBase
    {
        public UnaryFunction6()
        {
            this.Range = (-10, 10);
            this.Solve = SolveType.Min;
            this.Accuracy = 3;
        }

        public override double Func(params double[] xs)
        {
            double x = xs[0];
            double fx = 0;
            const int n = 100;
            const double a = 0.5d;
            const double b = 19;
            for (int i = 0; i <= n; i++)
            {
                fx += Math.Pow(a, i) * Math.Cos(Math.Pow(b, i) * Math.PI * x);
            }
            return fx;
        }
    }
}
